home *** CD-ROM | disk | FTP | other *** search
/ Champak 122 / Vol 122.iso / games / sketchbo.swf / scripts / DefineSprite_290 / frame_1 / DoAction.as
Encoding:
Text File  |  2011-01-06  |  6.7 KB  |  382 lines

  1. walking = false;
  2. parrying = false;
  3. slashing = false;
  4. jumping = false;
  5. speed = 0;
  6. turbo = 0;
  7. turnTo = "";
  8. stop();
  9. this.onEnterFrame = function()
  10. {
  11.    if(!init)
  12.    {
  13.       return undefined;
  14.    }
  15.    onWalk();
  16.    onRecieveHit();
  17.    doCalcs();
  18.    if(!walking && !slashing && !jumping && !parrying && !turning && !recieving && !dead)
  19.    {
  20.       unwalk();
  21.       gotoAndStop("stand");
  22.    }
  23. };
  24. doCalcs = function()
  25. {
  26.    if(!(walking || slashing || jumping || parrying || turning || recieving))
  27.    {
  28.       ki += regen_rate;
  29.    }
  30.    if(ki > total_ki)
  31.    {
  32.       ki = total_ki;
  33.    }
  34.    if(hp > total_hp)
  35.    {
  36.       hp = total_hp;
  37.    }
  38.    if(ki < 0)
  39.    {
  40.       ki = 0;
  41.    }
  42.    if(hp < 0)
  43.    {
  44.       hp = 0;
  45.    }
  46.    pic.bars.hp._xscale = Math.ceil(hp / total_hp * 100);
  47.    pic.bars.ki._xscale = Math.ceil(ki / total_ki * 100);
  48. };
  49. if(!init)
  50. {
  51.    pic = _root.pic_hitomi;
  52.    side = "R";
  53.    orig_scale = _xscale;
  54.    init = true;
  55.    total_hp = 100;
  56.    hp = total_hp;
  57.    total_ki = 100;
  58.    ki = total_ki;
  59.    regen_rate = 1;
  60.    last_attack_types = [];
  61. }
  62. getDirection = function()
  63. {
  64.    if(orig_scale == _xscale)
  65.    {
  66.       return 1;
  67.    }
  68.    return -1;
  69. };
  70. attack = function(type, ki_cost)
  71. {
  72.    if(jumping || slashing || recieving || dead)
  73.    {
  74.       return undefined;
  75.    }
  76.    if(turning)
  77.    {
  78.       completeTurn();
  79.    }
  80.    this.ki_cost = ki_cost;
  81.    m = 1;
  82.    if(type == last_attack_types[0])
  83.    {
  84.       m = 2;
  85.       if(type == last_attack_types[1])
  86.       {
  87.          m = 3;
  88.       }
  89.    }
  90.    last_attack_types.unshift(type);
  91.    if(last_attack_types.length > 5)
  92.    {
  93.       last_attack_types.pop();
  94.    }
  95.    if(ki_cost * m > ki)
  96.    {
  97.       return undefined;
  98.    }
  99.    turning = false;
  100.    slashing = true;
  101.    waswalking = walking;
  102.    walking = false;
  103.    speed = 0;
  104.    delete this.onWalk;
  105.    gotoAndPlay(type);
  106. };
  107. unattack = function()
  108. {
  109.    if(slashing)
  110.    {
  111.       ki -= ki_cost * m;
  112.    }
  113.    slashing = false;
  114.    if(waswalking || Key.isDown(39) && side == "R" || Key.isDown(37) && side == "L")
  115.    {
  116.       waswalking = false;
  117.       walking = false;
  118.       walk();
  119.    }
  120. };
  121. slash1 = function()
  122. {
  123.    attack("slash1",4);
  124. };
  125. slash2 = function()
  126. {
  127.    attack("slash2",5);
  128. };
  129. headslash = function()
  130. {
  131.    attack("headslash",15);
  132. };
  133. headslash2 = function()
  134. {
  135.    attack("headslash2",6);
  136. };
  137. jump = function()
  138. {
  139.    if(!jumping && !recieving && !slashing && !dead)
  140.    {
  141.       jumping = true;
  142.       if(walking)
  143.       {
  144.          unwalk();
  145.       }
  146.       turning = false;
  147.       slashing = false;
  148.       gotoAndStop("jump");
  149.       play();
  150.    }
  151. };
  152. backflip = function()
  153. {
  154.    if(!jumping && !recieving && !dead)
  155.    {
  156.       if(walking)
  157.       {
  158.          turning = false;
  159.          walking = false;
  160.          delete this.onWalk;
  161.          speed = 0;
  162.       }
  163.       turning = false;
  164.       slashing = false;
  165.       gotoAndStop("backflip");
  166.       play();
  167.    }
  168. };
  169. frontflip = function()
  170. {
  171.    if(!jumping && !recieving && !slashing && !dead)
  172.    {
  173.       jumping = true;
  174.       waswalking = walking;
  175.       if(walking)
  176.       {
  177.          turning = false;
  178.          walking = false;
  179.          delete this.onWalk;
  180.          speed = 0;
  181.       }
  182.       slashing = false;
  183.       if(!turning)
  184.       {
  185.          turning = false;
  186.          gotoAndStop("frontflip");
  187.          play();
  188.       }
  189.       else
  190.       {
  191.          turning = false;
  192.          gotoAndStop("backflip");
  193.          play();
  194.       }
  195.    }
  196. };
  197. right = function()
  198. {
  199.    turn("R");
  200. };
  201. left = function()
  202. {
  203.    turn("L");
  204. };
  205. turn = function(toside)
  206. {
  207.    if(slashing || recieving || dead)
  208.    {
  209.       return undefined;
  210.    }
  211.    if(side != toside)
  212.    {
  213.       if(!walking && !jumping && !turning && turnTo == "")
  214.       {
  215.          turnTo = toside;
  216.          turning = true;
  217.          walking = false;
  218.          jumping = false;
  219.          parrying = false;
  220.          speed = 0;
  221.          gotoAndStop("turn");
  222.          play();
  223.       }
  224.    }
  225.    else
  226.    {
  227.       turning = false;
  228.       walk();
  229.    }
  230. };
  231. completeTurn = function()
  232. {
  233.    side = turnTo;
  234.    turning = false;
  235.    if(turnTo == "L")
  236.    {
  237.       _xscale = - orig_scale;
  238.    }
  239.    else
  240.    {
  241.       _xscale = orig_scale;
  242.    }
  243. };
  244. turnTo = "";
  245. walk = function()
  246. {
  247.    if(walking || slashing || jumping || parrying || turning || recieving || dead)
  248.    {
  249.       return undefined;
  250.    }
  251.    walking = true;
  252.    gotoAndStop("walk");
  253.    play();
  254.    this.count = 0;
  255.    this.onWalk = function()
  256.    {
  257.       count++;
  258.       walking = true;
  259.       if(side == "R")
  260.       {
  261.          speed = 2 + turbo;
  262.       }
  263.       else
  264.       {
  265.          speed = - (2 + turbo);
  266.       }
  267.    };
  268. };
  269. unwalk = function()
  270. {
  271.    if(walking)
  272.    {
  273.       delete this.onWalk;
  274.       turning = false;
  275.       walking = false;
  276.       speed = 0;
  277.    }
  278.    if(slashing)
  279.    {
  280.       turning = false;
  281.       walking = false;
  282.       speed = 0;
  283.    }
  284.    if(waswalking)
  285.    {
  286.       waswalking = false;
  287.    }
  288. };
  289. parry = function()
  290. {
  291.    if(!parrying && !slashing && !jumping && !dead)
  292.    {
  293.       turning = false;
  294.       jumping = false;
  295.       parrying = true;
  296.       delete this.onWalk;
  297.       walking = false;
  298.       speed = 0;
  299.       gotoAndStop("parry");
  300.       play();
  301.    }
  302. };
  303. unparry = function()
  304. {
  305.    if(parrying)
  306.    {
  307.       delete this.onWalk;
  308.       turning = false;
  309.       parrying = false;
  310.       jumping = false;
  311.       slashing = false;
  312.       recieving = false;
  313.       walking = false;
  314.       speed = 0;
  315.       gotoAndStop("unparry");
  316.       play();
  317.    }
  318. };
  319. recieveHit = function(hit_by)
  320. {
  321.    if(recieving)
  322.    {
  323.       return undefined;
  324.    }
  325.    if(parrying)
  326.    {
  327.       if(getDirection() == hit_by.getDirection())
  328.       {
  329.          trace("defense!");
  330.          return undefined;
  331.       }
  332.    }
  333.    var _loc3_ = hit_by.damage;
  334.    fall_distance = hit_by.pushfactor;
  335.    hp -= _loc3_;
  336.    onRecieveHit = function()
  337.    {
  338.       fall_distance--;
  339.       if(fall_distance < 1)
  340.       {
  341.          delete this.onRecieveHit;
  342.          fall_distance = 0;
  343.          speed = 0;
  344.          return undefined;
  345.       }
  346.       _root.pan(-1 * hit_by.getDirection() * fall_distance);
  347.    };
  348.    recieving = true;
  349.    waswalking = walking;
  350.    gotoAndStop("recievehit");
  351.    play();
  352. };
  353. unRecieveHit = function()
  354. {
  355.    if(hp < 1)
  356.    {
  357.       dead = true;
  358.       delete this.onEnterFrame;
  359.       return undefined;
  360.    }
  361.    recieving = false;
  362.    turning = false;
  363.    slashing = false;
  364.    jumping = false;
  365.    parrying = false;
  366.    walking = false;
  367.    if(waswalking || Key.isDown(39) && side == "R" || Key.isDown(37) && side == "L")
  368.    {
  369.       waswalking = false;
  370.       walking = false;
  371.       walk();
  372.    }
  373.    else
  374.    {
  375.       gotoAndStop("stand");
  376.    }
  377. };
  378. playSound = function(ids)
  379. {
  380.    _root.sounds.playSound(ids);
  381. };
  382.